草庐IT

javascript - 动态 NG- Controller 名称

全部标签

ruby - 动态创建类

我正在尝试创建一个新类,但在创建类之前不知道该类的名称。类似这样的东西;variable="ValidClassName"classvariableendTest=ValidClassName.new如果可能的话,我也很感激关于如何向这个新类动态添加属性(和方法)的提示。我将检索类(class)的“设置”,它们看起来像这样:title:Personattribute:name,Stringattribute:age,Fixnum但不应设计为仅接受该显式文件,属性可能在数字结束类型上有所不同。最后会生成一个类似于下面这样的类:classPersondefinitialize(name,a

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby-on-rails - RSpec 找不到我的 Controller 未初始化的常量

我的Rails应用程序最近从Rails3迁移到Rails4,我一直在尝试在个别规范(Controller、模型等)上运行rspec,但它似乎在实际定位对象时遇到了问题。例如,当我尝试运行以下代码时,它会出现未初始化常量错误。这似乎发生在多个Controller上。我已经尝试删除rails_helper.rb和spec_helper.rb并运行railsgeneraterspec:install但它似乎没有解决错误。为什么找不到Controller?我要执行的操作->rspecspec/controllers/activity_controller_spec.rb/Users/osx_u

ruby-on-rails - Rails 5 Heroku 部署错误:ExecJS::ProgramError: SyntaxError: 意外的 token :名称(autoRegisterNamespace)

尝试将Rails5应用程序部署到heroku时,出现以下错误,当它到达Running:rakeassets:precompile时:remote:ExecJS::ProgramError:SyntaxError:Unexpectedtoken:name(autoRegisterNamespace)(line:14767,col:7,pos:457487)remote:Errorremote:atnewJS_Parse_Error(:3623:11948)remote:atjs_error(:3623:12167)remote:atcroak(:3623:21858)remote:att

ruby-on-rails - 使用 add_reference 时指定自定义索引名称

我有以下迁移classLinkDoctorsAndSpecializations当我运行rakedb:migrate时出现错误表“doctors”上的索引名称“index_doctors_on_doctor_specialization_type_and_doctor_specialization_id”太长;限制为63个字符那么在使用add_reference时如何指定索引名称,就像我们在add_index:table,:column,:name=>'indexname'中指定的那样 最佳答案 作为我commented,做:add

ruby-on-rails - Rails Controller 命名空间

在ruby​​onrails中使用命名空间的优点和缺点是什么。例如:我有很多像这样的ControllerCompanyLocationsCompanyXXXXCompanySportsCompanyActivitesCompanyQQQQQ我想将所有这些Controller放在公司文件夹中。Rails对此的最佳实践是什么? 最佳答案 您必须在您的controller/目录中创建一个子文件夹,并在您的views/目录中创建相同的子文件夹。你的Controller文件应该是这样的moduleCompanyclassSportsContr

ruby-on-rails - 名称错误 : uninitialized constant Factory

我正在关注thistutorial为了与工厂女孩、rspec一起开始使用TDDonrails,我遇到了这个问题,我无法理解。这是我的“工厂”.rb(events.rb)require'faker'FactoryGirl.definedofactory:eventdoname"HIGH"genre"house,techno,idb"venue_name"WestbourneStudios"venue_address"4-6ChamberlayneRoad"venue_postcode"NW103JD"begin_time"10pm"end_time"2am"user_id2descrip

ruby - 如何动态添加 attr_reader

我希望下面的代码能按预期工作,但它给了我一个NoMethodError(为#classMyClassendmy_object=MyClass.newmy_object.instance_variable_set(:@foo,"bar")MyClass.send("attr_reader",:foo)putsmy_object.foo问题是我在一个更大的应用程序中使用完全相同的代码并且它完全按照我的预期工作,但是当我将它简化为这个最基本的示例时它失败了。(我知道还有很多其他方法可以完成我在Ruby中所做的事情) 最佳答案 使用Modu

ruby-on-rails - 为什么 Rails titlecase 会在名称中添加空格?

为什么titlecase弄乱了名字?我有:JohnMarkMcMillan它变成了:>>"johnmarkMcMillan".titlecase=>"JohnMarkMcMillan"为什么姓氏后面要加空格?基本上我的模型中有这个:before_save:capitalize_namedefcapitalize_nameself.artist=self.artist.titlecaseend我试图确保数据库中的所有名称都是首字母大写,但在驼峰式名称的情况下它会失败。有什么解决办法吗? 最佳答案 如果Rails不够好,您可以自己做:c

ruby-on-rails - 具有不同 HTTP 请求类型的两个路由如何共享相同的名称?

在Rails3.2中,我使用这些路由声明:get'contact'=>'contact#new',:as=>'contact'post'contact'=>'contact#create',:as=>'contact'它们导致(rakeroutes):contact_enGET/en/contact(.:format)contact#new{:locale=>"en"}contact_deGET/de/kontakt(.:format)contact#new{:locale=>"de"}contact_enPOST/en/contact(.:format)contact#create{